package test;

import java.sql.Timestamp;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import backstage.competence.dao.CompetenceDao;
import backstage.competence.pojo.Competence;
import backstage.information.dao.InformationDao;
import backstage.information.pojo.Information;
import backstage.menu.dao.SysMenuDao;
import backstage.menu.pojo.SysMenu;
import backstage.staff.dao.StaffDao;
import backstage.staff.pojo.Staff;
import backstage.sys.util.*;

public class SetData {
	
	public static void main(String[] args) {
		ApplicationContext app = new FileSystemXmlApplicationContext("webapp/WEB-INF/conf/test.xml","webapp/WEB-INF/conf/applicationContext_sysmune.xml",
				"webapp/WEB-INF/conf/applicationContext_competence.xml","webapp/WEB-INF/conf/applicationContext_staff.xml",
				"webapp/WEB-INF/conf/applicationContext_information.xml");
		setStaff(app);
		setCompetence(app);
		setSysMenu(app);
		setInformation(app);
	}
	
	private static void setStaff(ApplicationContext app){
		StaffDao sd = (StaffDao) app.getBean("staffDao");
		
		Staff a = new Staff();
		a.setSysPwd(MD5.getMD5(MD5.getMD5("adminchlitina".getBytes()).getBytes()));
		a.setSysName("admin");
		a.setName("admin");
		a.setIdNumber("");
		a.setPhone("");
		a.setStatus(1);
		a.setStatusTime(new Timestamp(System.currentTimeMillis()));
		a.setEntryTime(new Timestamp(System.currentTimeMillis()));
		a.setEmployees(0);
		sd.seva(a);
		
		Staff s = new Staff();
		s.setSysPwd(MD5.getMD5(MD5.getMD5("adminchlitina".getBytes()).getBytes()));
		s.setSysName("kaiyuan");
		s.setName("kaiyuanshop");
		s.setIdNumber("");
		s.setPhone("");
		s.setStatus(1);
		s.setStatusTime(new Timestamp(System.currentTimeMillis()));
		s.setEntryTime(new Timestamp(System.currentTimeMillis()));
		s.setEmployees(0);
		sd.seva(s);
	}
	
	private static void setCompetence(ApplicationContext app){
		CompetenceDao cd = (CompetenceDao)app.getBean("competenceDao");
		
		Competence c1 = new Competence();
		c1.setName("超级管理员");
		c1.setGroupId("1111");
		StaffDao sd = (StaffDao) app.getBean("staffDao");
		Staff a = sd.getStaff("admin");
		c1.getStaffs().add(a);
		cd.seva(c1);
		
		Competence c2 = new Competence();
		c2.setName("管理员");
		c2.setGroupId("1000");
		cd.seva(c2);
		
		Competence c3 = new Competence();
		c3.setName("经理");
		c3.setGroupId("0111");
		cd.seva(c3);
		
		Competence c4 = new Competence();
		c4.setName("店长");
		c4.setGroupId("0110");
		cd.seva(c4);
		
		Competence c5 = new Competence();
		c5.setName("副店长");
		c5.setGroupId("0100");
		cd.seva(c5);
		
		Competence c6 = new Competence();
		c6.setName("指导老师");
		c6.setGroupId("0011");
		cd.seva(c6);
		
		Competence c7 = new Competence();
		c7.setName("店员");
		c7.setGroupId("0010");
		cd.seva(c7);
		
		Competence c8 = new Competence();
		c8.setName("公共");
		c8.setGroupId("0001");
		Staff s = sd.getStaff("kaiyuan");
		c1.getStaffs().add(s);
		cd.seva(c8);
		
	}
	
	private static void setSysMenu(ApplicationContext app){
		SysMenuDao sd = (SysMenuDao)app.getBean("sysMenuDao");
		
		SysMenu sm = new SysMenu();
		sm.setLabeling("Index");
		sm.setName("首页");
		sm.setUrl("backstage/home.jsp");
		sm.setOnlabeling("-1");
		sm.setState(1);
		sm.setOrders(0);
		sd.seva(sm);
		
		SysMenu sm1 = new SysMenu();
		sm1.setLabeling("1");
		sm1.setName("产品");
		sm1.setOnlabeling("-1");
		sm1.setState(1);
		sm1.setOrders(1);
		sd.seva(sm1);

		SysMenu sm2 = new SysMenu();
		sm2.setLabeling("2");
		sm2.setName("交易");
		sm2.setOnlabeling("-1");
		sm2.setState(1);
		sm2.setOrders(2);
		sd.seva(sm2);
		
		SysMenu sm3 = new SysMenu();
		sm3.setLabeling("3");
		sm3.setName("会员");
		sm3.setOnlabeling("-1");
		sm3.setState(1);
		sm3.setOrders(3);
		sd.seva(sm3);
		
		SysMenu sm4 = new SysMenu();
		sm4.setLabeling("4");
		sm4.setName("报表");
		sm4.setOnlabeling("-1");
		sm4.setState(1);
		sm4.setOrders(4);
		sd.seva(sm4);

		SysMenu sm5 = new SysMenu();
		sm5.setLabeling("5");
		sm5.setName("系统管理");
		sm5.setOnlabeling("-1");
		sm5.setState(1);
		sm5.setOrders(5);
		sd.seva(sm5);

		//会员
		SysMenu sm31 = new SysMenu();
		sm31.setLabeling("21");
		sm31.setName("会员查询");
		sm31.setOnlabeling("3");
		sm31.setState(1);
		sm31.setOrders(31);
		sd.seva(sm31);
		
		SysMenu sm32 = new SysMenu();
		sm32.setLabeling("22");
		sm32.setName("新增会员");
		sm32.setUrl("backstage/member/addMember.jsp");
		sm32.setOnlabeling("2");
		sm32.setState(1);
		sm32.setOrders(32);
		sd.seva(sm32);
		
		//系统管理
		SysMenu sm51 = new SysMenu();
		sm51.setLabeling("51");
		sm51.setName("消息管理");
		sm51.setOnlabeling("5");
		sm51.setState(1);
		sm51.setOrders(51);
		sd.seva(sm51);
		
		SysMenu sm52 = new SysMenu();
		sm52.setLabeling("52");
		sm52.setName("成员管理");
		sm52.setOnlabeling("5");
		sm52.setState(1);
		sm52.setOrders(52);
		sd.seva(sm52);
		
		SysMenu sm53 = new SysMenu();
		sm53.setLabeling("53");
		sm53.setName("组管理");
		sm53.setUrl("competenceAction.action");
		sm53.setOnlabeling("5");
		sm53.setState(1);
		sm53.setOrders(53);
		sd.seva(sm53);
		
		SysMenu sm54 = new SysMenu();
		sm54.setLabeling("54");
		sm54.setName("添加成员");
		sm54.setUrl("backstage/System/addStaff.jsp");
		sm54.setOnlabeling("5");
		sm54.setState(1);
		sm54.setOrders(54);
		sd.seva(sm54);
		
		SysMenu sm55 = new SysMenu();
		sm55.setLabeling("55");
		sm55.setName("修改密码");
		sm55.setUrl("backstage/System/updateStaffPwd.jsp");
		sm55.setOnlabeling("5");
		sm55.setState(1);
		sm55.setOrders(55);
		sd.seva(sm55);
		
	}
	
	private static void setInformation(ApplicationContext app){
		InformationDao id = (InformationDao)app.getBean("informationDao");
		
		Information attention = new Information();
		attention.setContent("Attention notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vulputate, sapien quis fermentum luctus, libero. ");
		attention.setInfotype("attention");
		attention.setStatus(1);
		id.seva(attention);
		
		Information information = new Information();
		information.setContent("Information notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vulputate, sapien quis fermentum luctus, libero.");
		information.setInfotype("information");
		information.setStatus(1);
		id.seva(information);
		
		Information success = new Information();
		success.setContent("Success notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vulputate, sapien quis fermentum luctus, libero.");
		success.setInfotype("success");
		success.setStatus(1);
		id.seva(success);
		
		Information error = new Information();
		error.setContent("Error notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vulputate, sapien quis fermentum luctus, libero.");
		error.setInfotype("error");
		error.setStatus(1);
		id.seva(error);
	}
}
